package org.dromara.tearoom.domain.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.enums.ArrayValuable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单状态
 *
 * @author ckj
 */
@AllArgsConstructor
@Getter
public enum OrderStatusEnum implements ArrayValuable<String> {

    NO_PAY("0", "待支付"),
    PAY("1","已确认"),
    OPEN_DOOR("2","已开门"),
    FINISHED("3","已完成"),
    CANCEL("4","已取消");


    /**
     * 类型
     */
    private final String type;

    /**
     * 描述
     */
    private final String description;

    // 静态映射表：用于快速根据 type 查找枚举实例
    private static final Map<String, OrderStatusEnum> TYPE_MAP = new HashMap<>();

    static {
        // 初始化映射表
        for (OrderStatusEnum enumItem : OrderStatusEnum.values()) {
            TYPE_MAP.put(enumItem.getType(), enumItem);
        }
    }


    public static final String[] ARRAYS = Arrays.stream(values()).map(OrderStatusEnum::getType).toArray(String[]::new);

    @Override
    public String[] array() {
        return ARRAYS;
    }

    /**
     * 根据 type 获取对应的 name
     * @param type 类型值
     * @return 对应的 name，若未找到返回 null
     */
    public static String getNameByType(String type) {
        OrderStatusEnum enumItem = TYPE_MAP.get(type);
        return enumItem != null ? enumItem.getDescription() : null;
    }



}
